package com.nafets.util;

import org.vaadin.hezamu.canvas.Canvas;

public class CanvasUtils {
	public static void drawArc(double x, double y, double radius, double startAngle, double endAngle, boolean fill, Canvas canvas, String color) {
		canvas.beginPath();
		canvas.arc(x, y, radius, (Math.PI / 180) * 0, (Math.PI / 180) * 360, false);
		if (fill) {
			canvas.setFillStyle(color);
			canvas.fill();
		} else {
			canvas.setStrokeColor(color);
			canvas.stroke();
		}
		
		canvas.closePath();
	}
	
	public static void drawLine(double x1, double y1, double x2, double y2, String color, Canvas canvas) {
		canvas.beginPath();
		canvas.setStrokeColor(color);
		canvas.moveTo(x1, y1);
		canvas.lineTo(x2, y2);
		canvas.closePath();
		canvas.stroke();
	}

	public static double drawLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4,
			double length, Canvas canvas) {
		double alpha = MathUtils.getAlpha(x1, y1, x2, y2, length);
		double x = MathUtils.getCoordinate(alpha, x1, x2);
		double y = MathUtils.getCoordinate(alpha, y1, y2);
		canvas.beginPath();
		canvas.moveTo(x, y);

		alpha = MathUtils.getAlpha(x3, y3, x4, y4, length);
		x = MathUtils.getCoordinate(alpha, x3, x4);
		y = MathUtils.getCoordinate(alpha, y3, y4);

		canvas.lineTo(x, y);
		canvas.closePath();
		canvas.stroke();
		
		return y;
	}
}
